package cn.biplam.front.component.view.systemManage.sysprivi.privilege.menu.manage.del;

import cn.biplam.common.ajxcode.SystemCode.MenuCode;
import cn.biplam.common.bean.md.IndexTable;
import cn.biplam.common.bean.systemManage.privi.MenuManageBean;
import cn.biplam.common.paramters.SysCaption;
import cn.biplam.common.paramters.TreeParam;
import cn.biplam.common.struc.SysStruc.PriviStruc;
import cn.biplam.common.wrapper.ErrorMessage;
import cn.biplam.common.wrapper.KvMap;
import cn.biplam.common.wrapper.UserInfo;
import cn.biplam.front.component.ComponentBase;
import cn.biplam.front.component.data.common.CaptionComp;
import cn.biplam.front.component.view.systemManage.sysprivi.privilege.menu.navi.MenuNavi;
import cn.biplam.front.html.HtmlDiv;
import cn.biplam.front.html.base.HtmlWindow;
import cn.biplam.front.htmlscript.script.ScriptTreeNew;
import cn.biplam.front.template.control.Confirm;

/**
 *  菜单删除界面和数据提交
 * @author XiaoRuxing Dec 9, 200912:14:13 PM
 * @version 1.0
 */
public class MenuDel extends ComponentBase{

	public MenuDel(UserInfo user, String homeUrl, String recordId,
			KvMap<String, String> params) {
		super(user, homeUrl, recordId, params);
	}

	/**
	 * @return 菜单删除提示界面
	 * @throws ErrorMessage 
	 */
	public HtmlWindow get() throws ErrorMessage{
		String recordId = params.getByKey(TreeParam.NODE_ID);
		IndexTable table = IndexTable.getNewInstance(mUser.getUserID(), PriviStruc.Table_Name, recordId);
		String menuName = table.getNodeName();
		if(menuName==null)menuName = recordId;
		
		StringBuilder sb = new StringBuilder();
		sb.append(CaptionComp.get(mUser, SysCaption.Confirm));
		sb.append(CaptionComp.get(mUser, SysCaption.Delete));
		sb.append(" ");
		sb.append(menuName);
		sb.append(" ?");
		
		/**生成提示信息窗口*/
		HtmlWindow win = null;
		Confirm delete = new Confirm(sb.toString(),recordId);
		delete.bind(MenuCode.Del_Menu_Submit);
		delete.putAddParams(TreeParam.NODE_CONTARINER_ID, 
				params.getByKey(TreeParam.NODE_CONTARINER_ID));
		win=delete.get();
		return win;
	}
	
	/**
	 * 菜单删除数据提交
	 * @return 刷新脚本
	 * @throws ErrorMessage 
	 */
	public HtmlWindow submit() throws ErrorMessage{
		//获取菜单操作类
		MenuManageBean menuOpt = MenuManageBean.getInstance(mUser.getUserID());
		//执行删除
		menuOpt.delete(recordId);
		//返回刷新脚本
		String script = ScriptTreeNew.getRefreshDelete(params.getByKey(TreeParam.NODE_CONTARINER_ID), 
				MenuNavi.Expand);
		HtmlWindow win = new HtmlDiv();
		win.bind(script);
		return win;
	}
}
